package backup;


import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

import cs6238.common.Configuration;

public class TestClient {

public static void main(String[] args){
		
		try{
			Configuration clientConfig = Configuration.loadClientSettings();
			int serverPort = Integer.parseInt(clientConfig.getSetting(Configuration.NETWORK_PORT));
			String serverAddress = clientConfig.getSetting(Configuration.SERVER_ADDRESS);
			
			String keyStorePath = clientConfig.getSetting(Configuration.KEYSTORE_PATH);
			String keyStorePassword = clientConfig.getSetting(Configuration.KEYSTORE_PASSWORD);
			String trustStorePath = clientConfig.getSetting(Configuration.TRUSTSTORE_PATH);
			String trustStorePassword = clientConfig.getSetting(Configuration.TRUSTSTORE_PASSWORD);
			
			//System.setProperty("javax.net.debug", "all");
			System.setProperty("javax.net.ssl.keyStore", keyStorePath);
			System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
			System.setProperty("javax.net.ssl.trustStore", trustStorePath);
			System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
			
			SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
			SSLSocket socket = (SSLSocket)socketFactory.createSocket(serverAddress, serverPort);
			socket.startHandshake();
			
			byte[] output = new byte[]{0,1,2,3,4,5,6,7,8,9};
			socket.getOutputStream().write(output);
			socket.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		System.out.println("All done");
	}
}
